package mapper;

import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.support.SqlSessionDaoSupport;
import pojo.entity.SysUser;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author 吴阳基
 * @datetime 2024/1/15 20:29
 */
public class SysUserMapperImpl extends SqlSessionDaoSupport implements SysUserMapper {
    private SqlSessionTemplate sqlSession;

    public List<SysUser> selectSysUserList(SysUser sysUser) {
        return this.getSqlSession().selectList("mapper.SysUserMapper.selectSysUserList", sysUser);
    }

    @Override
    public int getUserCount(String queryRealName, Integer queryRoleId) {
        return 0;
    }

    @Override
    public SysUser getUserById(Integer id) {
        return null;
    }

    public SqlSessionTemplate getSqlSession() {
        return sqlSession;
    }

    public void setSqlSession(SqlSessionTemplate sqlSession) {
        this.sqlSession = sqlSession;
    }


    @Override
    public int count() {
        return 0;
    }

    @Override
    public List<SysUser> getUserList(String queryRealName, Integer queryRoleId, Integer pageIndex, int pageSize) {
        return null;
    }

    @Override
    public int add(SysUser sysUser) {
        return 0;
    }

    @Override
    public List<SysUser> getUserList() {
        return null;
    }

    @Override
    public List<SysUser> getUserByRealName(String realName) {
        return null;
    }

    @Override
    public List<SysUser> getUserListByPojo(SysUser sysUser) {
        return null;
    }

    @Override
    public List<SysUser> getUserListByMap(Map<String, Object> userMap) {
        return null;
    }

    @Override
    public List<SysUser> getUserListByParams(String realName, int roleId) {
        return null;
    }

    @Override
    public List<SysUser> getUserListWithRoleName(SysUser sysUser) {
        return null;
    }

    @Override
    public List<SysUser> getUserListByRoleId(Integer roleId) {
        return null;
    }

    @Override
    public List<SysUser> getUserAndAddressesByUserId(Integer userId) {
        return null;
    }


    public int add(Connection connection, SysUser sysUser) {
        PreparedStatement pstm = null;
        int updateRows = 0;
        if (null != connection) {
            String sql = "insert into t_sys_user(account,realName,password,roleId,sex,birthday,phone,address,createdTime,createdUserId,idPicPath) " +
                    "values(?,?,?,?,?,?,?,?,?,?,?)";
            Object[] params = {sysUser.getAccount(),sysUser.getRealName(),
                    sysUser.getPassword(),sysUser.getRoleId(),
                    sysUser.getSex(),sysUser.getBirthday(),
                    sysUser.getPhone(),sysUser.getAddress(),
                    sysUser.getCreatedTime(),sysUser.getCreatedUserId(),sysUser.getIdPicPath()};
            try {
                pstm = connection.prepareStatement(sql);
                for (int i = 0; i < params.length; i++) {
                    pstm.setObject(i + 1, params[i]);
                }
                updateRows = pstm.executeUpdate();
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                try {
                    pstm.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
        return 1;
    }

    @Override
    public int modify(SysUser sysUser) {
        return 0;
    }

    @Override
    public int updatePwd(Integer id, String pwd) {
        return 0;
    }

    @Override
    public int deleteUserById(Integer id) {
        return 0;
    }

    @Override
    public List<SysUser> selectList(String realName, Integer roleId) {
        return null;
    }

    @Override
    public List<SysUser> selectListByChoose(String realName, Integer roleId, String account, Date createdTime) {
        return null;
    }

    @Override
    public List<SysUser> getUserByRoleIdArray(Integer[] roleIds) {
        return null;
    }

    @Override
    public List<SysUser> getUserByRoleIdList(List<Integer> roleId) {
        return null;
    }

    @Override
    public List<SysUser> getUserByRoleIdMap(Map<String, Object> map) {
        return null;
    }

    @Override
    public int update(SysUser user) {
        return 0;
    }

    @Override
    public List<SysUser> selectPageList(String realName, Integer roleId, Integer pageBegin, Integer pageSize) {
        return null;
    }
}
